#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    button = new QPushButton(this);
    button->move(200,200);
    button->setText("按钮");
    connect(button,&QPushButton::clicked,this,[=](){
        qDebug() << "lambda: 按钮被点击" << endl;
        QRect rect1 = this->frameGeometry();
        QRect rect2 = this->geometry();
        qDebug() << rect1;
        qDebug() << rect2;
    });

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_enable_clicked()
{
    button->setEnabled(false);
}

void Widget::on_pushButton_up_clicked()
{
    // 获取target的位置属性
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setY(rect.y() - 5);
//    ui->pushButton_target->setGeometry(rect);
    ui->pushButton_target->setGeometry(rect.x(),rect.y() - 5,rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    // 获取target的位置属性
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setX(rect.x() + 5);
//    ui->pushButton_target->setGeometry(rect);
        ui->pushButton_target->setGeometry(rect.x() + 5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    // 获取target的位置属性
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setY(rect.y() + 5);
//    ui->pushButton_target->setGeometry(rect);
    ui->pushButton_target->setGeometry(rect.x(),rect.y() + 5,rect.width(),rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    // 获取target的位置属性
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setX(rect.x() - 5);
//    ui->pushButton_target->setGeometry(rect);
      ui->pushButton_target->setGeometry(rect.x() - 5,rect.y(),rect.width(),rect.height());
}
